package chamber.coffeeshop;

/**
 * Created by Gerardo on 1/15/14.
 */
public class Waiter extends Thread {
    private void getCoffee() {
        synchronized (CoffeeMachine.lock) {
            if (CoffeeMachine.coffeeMade == null) {
                try {
                    System.out.println("waiter will get orders until the coffee machine notify");
                    CoffeeMachine.lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("waiter delivering: " + CoffeeMachine.coffeeMade);
                CoffeeMachine.coffeeMade = null;
                CoffeeMachine.lock.notifyAll();
                System.out.println("waiter notifying coffee machine to make another coffee");
            }
        }
    }

    @Override
    public void run() {
        while (true) {
            getCoffee();
        }
    }
}
